home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / Mesa-3.0 / SRC / FIXED.H < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-31  |  1.9 KB  |  67 lines

  1. /* $Id: fixed.h,v 3.0 1998/01/31 20:53:05 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  3.0
  6.  * Copyright (C) 1995-1998  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: fixed.h,v $
  26.  * Revision 3.0  1998/01/31 20:53:05  brianp
  27.  * initial rev
  28.  *
  29.  */
  30.  
  31.  
  32. #ifndef FIXED_H
  33. #define FIXED_H
  34.  
  35.  
  36. typedef int GLfixed;
  37.  
  38. #define FIXED_ONE       0x00000800
  39. #define FIXED_HALF      0x00000400
  40. #define FIXED_FRAC_MASK 0x000007FF
  41. #define FIXED_INT_MASK  (~FIXED_FRAC_MASK)
  42. #define FIXED_EPSILON   1
  43. #define FIXED_SCALE     2048.0f
  44. #define FIXED_SHIFT     11
  45. #define FloatToFixed(X) ((GLfixed) ((X) * FIXED_SCALE))
  46. #define IntToFixed(I)   ((I) << FIXED_SHIFT)
  47. #define FixedToInt(X)   ((X) >> FIXED_SHIFT)
  48. #define FixedToUns(X)   (((unsigned int)(X)) >> 11)
  49. #define FixedCeil(X)    (((X) + FIXED_ONE - FIXED_EPSILON) & FIXED_INT_MASK)
  50. #define FixedFloor(X)   ((X) & FIXED_INT_MASK)
  51. /* 0.00048828125 = 1/FIXED_SCALE */
  52. #define FixedToFloat(X) ((X) * 0.00048828125f)
  53. #define PosFloatToFixed(X)      FloatToFixed(X)
  54. #define SignedFloatToFixed(X)   FloatToFixed(X)
  55.  
  56.  
  57. #if DEPTH_BITS==16
  58. /* use fixed-point interpolation */
  59. #define FixedToDepth(I) ((I) >> FIXED_SHIFT)
  60. #else
  61. /* don't really use fixed-point */
  62. #define FixedToDepth(I) (I)
  63. #endif
  64.  
  65.  
  66. #endif
  67.